<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改课程')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-subject-edit" th:object="${adminSubject}">
            <input name="subjectId" th:field="*{subjectId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程名称：</label>
                <div class="col-sm-8">
                    <input name="subjectName" th:field="*{subjectName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程类型：</label>
                <div class="col-sm-8">
                    <select name="bookLevel" class="form-control m-b" th:with="type=${@dict.getType('sys_level')}">
                        <option  th:text="标准课程" th:value="1" ></option>
                    </select>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label">封面图片：</label>
                <div class="col-sm-6">
                    <input class="form-control" type="file" name="file" id="file" accept="image/*">
                </div>
                <div class="col-sm-2">
                    <button class="btn btn-success fileinput-button" type="button" id="btnimage">上传</button>
                </div>
            </div>

            <div class="form-group"  id="imgDiv" name="imgDiv">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <img class="img-square img-lg" name="imgUrl" id="imgUrl" th:src="*{coverPicture}">
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">课程级别：</label>
                <div class="col-sm-8">
                    <select name="subjectLevel" class="form-control m-b" th:with="type=${@dict.getType('sys_level')}">
                        <option>请选择教材级别：</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{subjectLevel}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sortNo" th:field="*{sortNo}" class="form-control" type="text">
                </div>
            </div>


            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_able_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/subject";
        $("#form-subject-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-subject-edit').serialize());
                var data = $("#form-subject-edit").serializeArray();
	        	data.push({"name": "coverPicture", "value": $("#imgUrl")[0].src});
	        	$.operate.save(prefix + "/edit", data);
            }
        }


        $('#btnimage').click(function() {
            var val = $("#file").val();
            if (val.length==0) {
                layer.alert("未选择图片");
                return ;
            }
            var formdata = new FormData();
            formdata.append("file", document.getElementById("file").files[0]);
            $.ajax({
                url: ctx + "system/upload/pictrue",
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function(result) {
                	$("#imgUrl").attr('src',result);
                	$("#file").val(result);//赋值
                }
            });
        });
    </script>
</body>
</html>